---
title: 'hash | Cypress Documentation'
description: Get the current URL hash of the page that is currently active in Cypress.
sidebar_label: hash
e2eSpecific: true
slug: /api/commands/hash
---

<ProductHeading product="app" />

# hash

Get the current URL hash of the page that is currently active.

:::info

This is an alias of [`cy.location('hash')`](/api/commands/location)

:::

## Syntax

```javascript
cy.hash()
cy.hash(options)
```

### Usage

<Icon name="check-circle" color="green" /> **Correct Usage**

```javascript
cy.hash() // Get the url hash
```

### Arguments

<Icon name="angle-right" /> **options _(Object)_**

Pass in an options object to change the default behavior of `cy.hash()`.

**cy.hash( _options_ )**

| Option    | Default                                                           | Description                                                                         |
| --------- | ----------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| `log`     | `true`                                                            | Displays the command in the [Command log](/app/core-concepts/open-mode#Command-Log) |
| `timeout` | [`defaultCommandTimeout`](/app/references/configuration#Timeouts) | Time to wait for `cy.hash()` to resolve before [timing out](#Timeouts)              |

<HeaderYields />

- When the current URL contains a hash, `cy.hash()` yields the current URL's
  hash (including the `#` character).
- When the current URL does not contain a hash, `cy.hash()` yields an empty
  string.
- `cy.hash()` is a query, and it is _safe_ to chain further commands.

## Examples

### No Args

#### Assert that hash is `#/users/1` given remote URL: `http://localhost:8000/app/#/users/1`

```javascript
// yields #/users/1
cy.hash().should('eq', '#/users/1') // => true
```

#### Assert that the hash matches via RegExp

```html
<ul id="users">
  <li>
    <a href="#/users/8fc45b67-d2e5-465a-b822-b281d9c8e4d1">Fred</a>
  </li>
</ul>
```

```javascript
cy.get('#users li').find('a').click()
cy.hash().should('match', /users\/.+$/) // => true
```

## Rules

<HeaderRequirements />

- `cy.hash()` requires being chained off of `cy`.

<HeaderAssertions />

- `cy.hash()` will automatically [retry](/app/core-concepts/retry-ability)
  until all chained assertions have passed

<HeaderTimeouts />

- `cy.hash()` can time out waiting for assertions you've added to pass.

## Command Log

**_Assert that the hash matches `#users/new`_**

```javascript
cy.hash().should('eq', '#users/new')
```

The commands above will display in the Command Log as:

<DocsImage
  src="/img/api/hash/test-url-hash-for-users-page.png"
  alt="Command Log for hash"
/>

When clicking on `hash` within the command log, the console outputs the
following:

<DocsImage
  src="/img/api/hash/hash-command-yields-url-after-hash.png"
  alt="Console Log for hash"
/>

## See also

- [`cy.location()`](/api/commands/location)
- [`cy.url()`](/api/commands/url)
